//
//  RSMessageModel.swift
//  ChatDemo
//
//  Created by 范强伟 on 2024/5/7.
//

import UIKit
import RealmSwift
/*!
 @enum
 @brief 聊天类型
 @constant MessageBodyType_Text 文本类型
 @constant MessageBodyType_Image 图片类型
 @constant MessageBodyType_Video 视频类型
 @constant MessageBodyType_Location 位置类型
 @constant MessageBodyType_Voice 语音类型
 @constant MessageBodyType_File 文件类型
 @constant MessageBodyType_Command 命令类型
 */
enum MessageBodyType: Int {
    case Text = 0
    case Image
    case Voice
    case Video
    case Location
    case File
    case Command
}

/*!
 @enum
 @brief 聊天消息发送状态
 @constant MessageDeliveryState_Pending 待发送
 @constant MessageDeliveryState_Delivering 正在发送
 @constant MessageDeliveryState_Delivered 已发送, 成功
 @constant MessageDeliveryState_Failure 已发送, 失败
 */

class RSMessageModel: Object {

    ///  飞行数据
    var contentList = List<RSMessageContentModel>()
    
    ///  聊天id
    @objc dynamic var roomId: String = ""
    
    // 主键
    override class func primaryKey() -> String? {
        return "roomId"
    }
}

class RSMessageContentModel: Object {
    /// LinkingObjects 反向表示该对象的拥有者
    let owners = LinkingObjects(fromType: RSMessageModel.self, property: "contentList")
    
    
    /// 消息id
    @objc dynamic var messageId: String = "\(milliStamp)"
    
    /** 是否是发送者 */
    @objc dynamic var isSender: Bool = false
    /** 是否已读 */
    @objc dynamic var isRead : Bool = false
    /** 是否是群聊 */
    @objc dynamic var isChatGroup: Bool = false
    /// 用户名称
    @objc dynamic var userName: String = ""
    // 用户头像
    @objc dynamic var userHeader: String = ""
    /// 消息类型
    @objc dynamic var type: Int = 0
    /// 消息状态 CLChatMessageSendState
    @objc dynamic var status :Int = 0
    /// 发送时间
    @objc dynamic var date: Int64 = milliStamp
     
    
    /** text */
    @objc dynamic  var content : String = ""

    /** image */
    @objc dynamic var width: Float = 0
    @objc dynamic var height: Float = 0
    @objc dynamic var imageURL: String = ""
    
    /**voice**/
    @objc dynamic var duration: Float = 0
    @objc dynamic var voiceUrl: String = ""
    
    // 主键
    override class func primaryKey() -> String? {
        return "messageId"
    }
}

